<style lang="less">

@import '../../styles/common.less';

</style>

<template>

<div>
    <Row>
        <Card>
            <Form ref="build" :model="build" :rules="buildRules" :label-width="120">
                <FormItem label="楼宇名称：" prop="name">
                    <Input v-model="build.name" type="text" placeholder="请输入楼宇名称..."></Input>
                </FormItem>
                <FormItem label="楼宇地址：">
                    <Input v-model="build.address" type="text" placeholder="请输入楼宇地址..."></Input>
                </FormItem>
                <FormItem label="产权方名称：">
                    <Input v-model="build.attribution" type="text" placeholder="请输入产权方名称..."></Input>
                </FormItem>
                <FormItem label="物业名称：">
                    <Input v-model="build.property" type="text" placeholder="请输入物业名称..."></Input>
                </FormItem>
                <FormItem label="楼宇高度：">
                    <InputNumber :max="100" :min="1" v-model="build.floor"></InputNumber>
                </FormItem>
                <FormItem label="所属园区名称：">
                    <Input v-model="build.park" type="text" placeholder="请输入所属园区名称..."></Input>
                </FormItem>
                <FormItem label="备注：">
                    <Input v-model="build.remake" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入备注..."></Input>
                </FormItem>
                <FormItem>
                    <Button type="primary" :loading="loading" @click="handleSubmit('build')">提交</Button>
                    <Button type="ghost" @click="handleReset('build')" style="margin-left: 8px">Reset</Button>
                </FormItem>
            </Form>
        </Card>
    </Row>
</div>

</template>

<script>
import {
  addBuild
} from 'api/build/build';
export default {
    name: 'workflow',
    data() {
        return {
            loading:false,
            build: {
                address: '',
                attribution: '',
                floor: 1,
                name: '',
                park: '',
                property: '',
                remake: ''
            },
            buildRules: {
                name: [{
                    required: true,
                    message: '请输入楼宇名称',
                    trigger: 'blur'
                }]
            }
        };
    },
    methods: {
        handleSubmit(from) {
            this.$refs[from].validate((valid) => {
                if (valid) {
                  this.loading = true;
                    addBuild(this.build).then(data => {
                      this.loading = false;
                      if (data.status === 200) {
                        this.$refs[from].resetFields();
                        this.$Message.success('添加成功');
                      } else {
                        this.$Message.error(data.message);
                      }
                    }).catch(error => {
                        this.loading = false;
                        this.$Message.error('服务器异常' + error);
                    });
                } else {
                    this.$Message.error('请输入完整信息');
                }
            });
        },
            handleReset (name) {
                this.$refs[name].resetFields();
            }
    }
};

</script>
